﻿#pragma once
#include "core/SWnd.h"

namespace SOUI {
    class SOUI_EXP SSpinButtonCtrl : public SWindow {
        SOUI_CLASS_NAME(SSpinButtonCtrl, L"spinButton")
      public:
        SSpinButtonCtrl(void);
        ~SSpinButtonCtrl(void);
        
        
      public:
        void SetStep(double fStep);
        
      protected:
        virtual CSize GetDesiredSize(int wid, int hei);
        virtual BOOL NeedRedrawWhenStateChange() {
            return TRUE;
        }
        virtual void OnColorize(COLORREF cr);
        
      protected:
        void OnValueChanged(bool bInit = false);
        
        void OnLButtonDown(UINT nFlags, CPoint point);
        void OnLButtonUp(UINT nFlags, CPoint point);
        void OnMouseMove(UINT nFlags, CPoint point);
        void OnPaint(IRenderTarget *pRT);
        void OnTimer(char cTimerId);
        int OnCreate(void *);
        void OnClick();
        
        SOUI_MSG_MAP_BEGIN()
        MSG_WM_CREATE(OnCreate)
        MSG_WM_LBUTTONDOWN(OnLButtonDown)
        MSG_WM_LBUTTONDBLCLK(OnLButtonDown)
        MSG_WM_MOUSEMOVE(OnMouseMove)
        MSG_WM_LBUTTONUP(OnLButtonUp)
        MSG_WM_PAINT_EX(OnPaint)
        MSG_WM_TIMER_EX(OnTimer)
        SOUI_MSG_MAP_END()
        
      protected:
        HRESULT OnAttrValue(const SStringW &strValue, BOOL bLoading);
        
        void OnSkinChanged();
        
        
        SOUI_ATTRS_BEGIN()
        ATTR_FLOAT(L"max", m_nMax, FALSE)
        ATTR_FLOAT(L"min", m_nMin, FALSE)
        ATTR_CUSTOM(L"value", OnAttrValue)
        ATTR_FLOAT(L"step", m_uStep, FALSE)
        ATTR_INT(L"circle", m_bCircle, FALSE)
        ATTR_SKIN(L"upskin", m_pUpSkin, TRUE)
        ATTR_SKIN(L"downSkin", m_pDownSkin, TRUE)
        SOUI_ATTRS_END()
        
      protected:
        float m_nMax;
        float m_nMin;
        float m_nValue;
        int     m_Unit = 0;
        float m_uStep;
        
        BOOL m_bCircle;
        
        ISkinObj *m_pUpSkin = nullptr;
        ISkinObj *m_pDownSkin = nullptr;
        
        enum ActionButton {
            ACTION_NULL = -1,
            ACTION_UP,
            ACTION_DOWN,
        };
        ActionButton              m_iActionBtn;
    };
}
